﻿using System;
using System.IO;
using LZX.MEditor.LZXStatic;
using LZX.MEditor.MScriptableObject;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;

namespace LZX.MEditor.Window.Item
{
    public class RunTimeAsset:RunTimeItemBase
    {
        public Asset Asset;
        public RunTimeAsset(Asset asset,VisualElement scv)
        {
            Group.style.display = DisplayStyle.None;
            Asset = asset;
            Name.text = asset.LoadPath;
            SizeDropDown.index = 0;
            scv.Add(root);
            InitDependecies();
            ParseBG();
        }
        private void InitDependecies()
        {
            foreach (var dep in Asset.Dependences)
            {
                Asset depAsset = new Asset(AssetDatabase.AssetPathToGUID(dep));
                RunTimeAsset deps = new RunTimeAsset(depAsset,DependenciesContainer);
            }
        }
        private void ParseBG()
        {
            string ext = Path.GetExtension(Asset.LoadPath);
            switch (ext)
            {
                case ".prefab":
                    BG.style.backgroundImage = LZXEditorResources.GetIcon(LZXIconType.prefab);
                    break;
                case ".mp3":
                case ".wav":
                    BG.style.backgroundImage = LZXEditorResources.GetIcon(LZXIconType.music);
                    break;
                case ".png":
                case ".jpg":
                    BG.style.backgroundImage = AssetDatabase.LoadAssetAtPath<Texture2D>(Asset.LoadPath);
                    break;
                case ".asset":
                case ".json":
                case ".txt":
                case ".bytes":
                case ".cs":
                    BG.style.backgroundImage = LZXEditorResources.GetIcon(LZXIconType.cs);
                    break;
                case ".unity":
                    BG.style.backgroundImage = LZXEditorResources.GetIcon(LZXIconType.scene);
                    break;
            }
        }
    }
}